package com.cloudtasks.server;

import java.util.List;

import com.cloudtasks.annotation.ServiceMethod;
import com.cloudtasks.shared.TaskChange;


public class CloudTasksService {

	DataStore ds = new DataStore();
	
	@ServiceMethod
	public Task createTask() {
		return ds.update(new Task());
	}

	@ServiceMethod
	public Task readTask(Long id) {
		return ds.find(id);
	}

	@ServiceMethod
	public Task updateTask(Task task) {
		task.setEmailAddress(DataStore.getUserEmail());
		task = ds.update(task);
		DataStore.sendC2DMUpdate(TaskChange.UPDATE + TaskChange.SEPARATOR + task.getId());
		return task;
	}

	@ServiceMethod
	public void deleteTask(Task task) {
		ds.delete(task.getId());
	}

	@ServiceMethod
	public List<Task> queryTasks() {
		return ds.findAll();
	}

}
